//
//  BarGraphTableViewCell.swift
//  ZNZXSuperMarket
//
//  Created by 四川中农 on 2018/8/6.
//  Copyright © 2018年 四川中农. All rights reserved.
//

import UIKit

class BarGraphTableViewCell: UITableViewCell {
    
    var chartViewbar:LCChartView!
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var firstLabel: UILabel!
    @IBOutlet weak var secondLabel: UILabel!
    

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        self.chartViewbar = LCChartView.init(frame: CGRect.init(x: 0, y: 35, width: UIScreen.ScreenWidth, height: 216 - 35), chartViewType: .bar)
        self.chartViewbar.xAxisTitleArray = ["标类","果蔬类","生鲜类"]
        self.addSubview(self.chartViewbar)
    }
    
    func reloadWith(wwithLastModel lastModel:OrderStatisModel, model:OrderStatisModel,type:Int){
        
        var value1 = ("","")
        var value2 = ("","")
        var value3 = ("","")
        
        if lastModel.biao != nil {
            value1.0 = "\(lastModel.biao.bMoney)"
        }
        if model.biao != nil {
            value1.1 = "\(model.biao.bMoney)"
        }
        if lastModel.fruits != nil {
            value2.0 = "\(lastModel.fruits.gMoney)"
        }
        if model.fruits != nil {
            value2.1 = "\(model.fruits.gMoney)"
        }
        if lastModel.fresh != nil {
            value3.0 = "\(lastModel.fresh.sMoney)"
        }
        if model.fresh != nil {
            value3.1 = "\(model.fresh.sMoney)"
        }
        
        let model1 = LCChartViewModel.init(color: UIColor.init(hexColor: "#79add1"), plots:[value1.0,value2.0,value3.0], project: "")
        let model2 = LCChartViewModel.init(color: UIColor.init(hexColor: "#f7c201"), plots:[value1.1,value2.1,value3.1], project: "")
        
        self.chartViewbar.show(withYAxisMaxValue: 10000, dataSource: [model1!,model2!])
        
        if type == 0 {
            self.firstLabel.text = "本月：" + "\(model.money)元"
            self.secondLabel.text = "上月：" + "\(lastModel.money)元"
        }else{
            self.firstLabel.text = "本周：" + "\(model.money)元"
            self.secondLabel.text = "上周：" + "\(lastModel.money)元"
        }
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
